/* 
 * AndFollowerStat
 * 
 * Copyright (C) 2009  Daniel Czerwonk <d.czerwonk@googlemail.com>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package de.dan_nrw.android.followerstat.client.configuration;

import com.google.inject.Inject;

import de.dan_nrw.android.followerstat.DependencyInjector;
import de.dan_nrw.android.followerstat.R;
import de.dan_nrw.android.followerstat.dao.configuration.IConfigDAO;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;


/**
 * @author Daniel Czerwonk
 *
 */
public class ConfigActivity extends Activity {
		
	private final IConfigDAO configDAO;
	
	public static int RETURN_CODE_OK = 1;
	
	
	/**
	 * Creates a new instance of ConfigActivity.
	 */
	@Inject
	public ConfigActivity() {
		this.configDAO = DependencyInjector.getInstance(IConfigDAO.class);
    }
    
    
    /* (non-Javadoc)
     * @see android.app.Activity#onCreate(android.os.Bundle)
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        this.setTitle(String.format("%s: %s", 
        							this.getString(R.string.applicationName), 
        							this.getString(R.string.settingsText)));
        
        this.setContentView(R.layout.settings);
        
        Button okButton = (Button)this.findViewById(R.id.okButton);
        
        okButton.setOnClickListener(new View.OnClickListener() {

			@Override
            public void onClick(View v) {
				saveChanges();
				
				setResult(1);
				
				finish();
            }
        });
        
        Button cancelButton = (Button)this.findViewById(R.id.cancelButton);
        
        cancelButton.setOnClickListener(new View.OnClickListener() {

			@Override
            public void onClick(View v) {
				setResult(0);
				
				finish();
            }        	
        });
        
        this.getUsernameEditText().setText(this.configDAO.getTwitterUserName());
    }
    
    private EditText getUsernameEditText() {
    	return (EditText)this.findViewById(R.id.userNameEditText);
    }
    
	private void saveChanges() {
		this.configDAO.setTwitterUserName(this.getUsernameEditText().getText().toString());
    }
}